<template>
	<div name="detailBanke">
		
		<van-nav-bar
			:title="detailBankeInfo.name"
			left-arrow
			left-text="返回"
			:right-text="rightText"
			fixed
			@click-left="$router.push({name: 'home'})"
		/>
		
		<!-- <bkSource v-if="tabbarTempValue === 0" ></bkSource> -->
		<bkMember v-if="tabbarTempValue === 0" ></bkMember>
		<!-- <bkNotice v-if="tabbarTempValue === 2" ></bkNotice> -->
		<bkDetails v-if="tabbarTempValue === 1" @toParent="rmCourse"></bkDetails>
		
		<van-tabbar v-model="tabbarTempValue">
			<!-- <van-tabbar-item  icon="point-gift-o"  >资源</van-tabbar-item> -->
			<van-tabbar-item  icon="friends-o"  >成员</van-tabbar-item>
			<!-- <van-tabbar-item  icon="smile-comment-o"  >公告</van-tabbar-item> -->
			<van-tabbar-item  icon="qr">详情</van-tabbar-item>
		</van-tabbar>
		
	</div>
</template>

<script>
	import { Dialog } from 'vant';
	import bkDetails from '@/components/detailBk/bkDetails.vue';
	import bkMember from '@/components/detailBk/bkMember.vue';
	// import bkNotice from '@/components/detailBk/bkNotice.vue';
	// import bkSource from '@/components/detailBk/bkSource.vue';
	import {quitCourse} from '@/api/member.js';
	import { removeCourse } from '@/api/course.js';
	export default {
		name: 'detailBanke',
		components: {
			bkDetails,
			bkMember,
			// bkNotice,
			// bkSource
		},
		created() {
			this.detailBankeInfo = JSON.parse(localStorage.getItem('detailBankeInfo'));
			if(this.$route.params.tabbarTempValue)
				this.tabbarTempValue = this.$route.params.tabbarTempValue;
			
		},
		data(){
			return {
				
				tabbarTempValue: 0,
				// bkInfo: this.detailBankeInfo.name,
				userInfo: JSON.parse(localStorage.getItem('userInfo')),
				detailBankeInfo: {}
			}
		},
		computed: {
			rightText() {
				// if(this.userInfo.roles[0] === 'TEACHER'){ // teacher
				// 	if(this.tabbarTempValue === 0) { return '上传资源';}
				// 	else if(this.tabbarTempValue === 2) { return '发布公告';}
				// 	else return '';
				// } else {
				// 	return '';
				// }
				return "";
			}
		},
		methods: {
			// ↓↓↓↓  根据子组件传来的事件 解散课程或退出课程
			rmCourse(msg) {
				Dialog.confirm({
					title: msg==='rmCourse'?'确认解散班课嘛？':'确认退出班课嘛？',
					message: '',
				}).then(() => {
					// on confirm
					if(msg === 'rmCourse') {
						removeCourse(this.detailBankeInfo.id).then(res => {
							console.log(res);
							if(res.data.code === 0) {
								this.$toast('解散成功');
								setTimeout(() => {
									this.$router.push({name: "home"});
								},100);
							}
						});
					} else if(msg === 'quitCourse') {
						quitCourse(this.detailBankeInfo.id).then(res => {
							console.log(res);
							if(res.data.code === 0) {
								this.$toast('退出成功');
								
							} else {
								this.$toast(res.data.msg);
								
							}
							setTimeout(() => {
								this.$router.push({name: "home"});
							},100);

						}).catch(err => console.log(err));
					}
				}).catch(() => {
					// on cancel
				});
				
			}
		}
	}
</script>

<style>
</style>
